home *** CD-ROM | disk | FTP | other *** search
- //: C17:RevStr.cpp
- // From Thinking in C++, 2nd Edition
- // Available at http://www.BruceEckel.com
- // (c) Bruce Eckel 1999
- // Copyright notice in Copyright.txt
- // Print a string in reverse
- #include <string>
- #include <iostream>
- using namespace std;
- int main() {
- string s("987654321");
- // Use this iterator to walk backwards:
- string::reverse_iterator rev;
- // "Incrementing" the reverse iterator moves
- // it to successively lower string elements:
- for(rev = s.rbegin(); rev != s.rend(); rev++)
- cout << *rev << " ";
- } ///:~
-